<?php

namespace App\Admin\Extensions;

use Encore\Admin\Admin;

class Has_pay
{
    protected $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

    protected function script()
    {
        return <<<SCRIPT
        //隐藏的点击事件
        $(document).on('click', '.btn-success', function() {
            //获取的ID
            var id = $(this).data('id');
            swal({
			  title: '通过',
			  text: '请输入转账流水号',
			  input: 'text',
			  inputAttributes: {
				autocapitalize: 'off'
			  },
			  showCancelButton: true,
			  confirmButtonText: '确认',
			  cancelButtonText: '取消',
			  showLoaderOnConfirm: true,			  
			}).then((result) => {
			  if (result.value) {
				$.ajax({
                    type: 'post',
                    url: '/admin/withdraw/has_pay',
                    data: {
                        id:id,
                        water_num:result.value,
                        //post请求token
                        _token:LA.token,
                    },
                    success: function (data) {
                        $.pjax.reload('#pjax-container');
                        if (typeof data === 'object') {
                            if (data.code == 1) {
                                swal(data.msg, '', 'success');
                            } else {
                                swal(data.msg, '', 'error');
                            }
                        }
                    }
                });  			
			  }else{
				swal('错误', '请输入不通过原因', 'error');  
			  }
			})
        });



        
SCRIPT;
    }

    protected function render()
    {
        Admin::script($this->script());
        
        return "<button type='button' class='btn btn-success' data-id='{$this->id}'>通过</button>";
    }

    public function __toString()
    {
        return $this->render();
    }
}